<template>
  <div class="template-section">
    <section class="content-center">
      <div class="goods-item" v-for="(item, index) in goodsList" :key="index">
        <!-- goodsBoxStyle -->
        <div class="goods-box" :style="goodsItemSpace">
          <!-- goodsItemSpace -->
          <div class="goods-fill-box" :style="goodsBoxStyle">
            <div class="goods-banner">
              <img v-if="item.cover_pic" :src="item.cover_pic" alt="" />
              <img
                v-else
                class="default-img"
                src="@/assets/images/diy/default_img.png"
                alt=""
              />
            </div>
            <div class="goods-info">
              <div style="position: relative;">
                <p
                  class="goods-name"
                  :style="{ color: propsData.params.producNameColor }"
                >
                  {{ item.name }}
                </p>
                <div class="price-box">
                  <span
                    class="price"
                    :style="{ color: propsData.params.priceColor }"
                  >
                    <span>￥</span>
                    <span>{{ item.price | priceBeforeZero }}</span>
                    <span>{{ item.price | priceAfterZero }}</span>
                  </span>
                  <span
                    class="origin-price"
                    v-if="propsData.params.showPrice"
                    :style="{ color: propsData.params.originPriceColor }"
                    >￥{{ item.original_price }}</span
                  >
                </div>
                <p
                  class="sales"
                  v-if="propsData.params.showSales"
                  :style="{ color: propsData.params.saleColor }"
                >
                  已售 {{ item.sales || 0 }}
                </p>
                <div
                  class="buy-btn"
                  :style="
                    propsData.params.buyStyle == 'add'
                      ? 'background: #fa2c1b;'
                      : ''
                  "
                  v-if="propsData.params.showBuyBtn"
                >
                  <i
                    v-if="propsData.params.buyStyle == 'add'"
                    class="iconfont icon-jiahao"
                  ></i>
                  <!-- <i
                    v-if="propsData.params.buyStyle == 'cart'"
                    class="iconfont icon-weibiaoti-14"
                  ></i> -->
                  <img
                    style="width: 100%"
                    v-if="
                      propsData.params.buyStyle == 'cart' &&
                      propsData.params.buyBtnImg
                    "
                    :src="propsData.params.buyBtnImg"
                    alt=""
                  />
                </div>
                <div v-if="propsData.params.buyStyle == 'word'" class="buy-text">
                  {{ propsData.params.buyBtnText || "购买" }}
                </div>
              </div>
              <div class="storeInfo" v-if="item.storeInfo">
                <div class="pic">
                  <img :src="item.storeInfo.logo" alt="">
                </div>
                <div class="info">
                  <span>{{item.storeInfo.name}}</span>
                  <span>营业时间 {{item.storeInfo.s_time}}-{{item.storeInfo.e_time}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
    goodsList: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {};
  },
  mounted() {},
  filters: {
    priceBeforeZero(val) {
      if (val.indexOf(".") < 0) return `${val}.`;
      return val.substr(0, val.indexOf("."));
    },
    priceAfterZero(val) {
      if (val.indexOf(".") < 0) return "00";
      return val.substr(val.indexOf("."), val.length);
    },
  },
  watch: {},
  computed: {
    goodsItemSpace() {
      let out = this.propsData.params.goodsItemOutSpace || "0";
      let css = {};
      if (out) {
        css["margin"] = `0 ${out / 2}px ${out}px`;
      }
      return css;
    },
    goodsBoxStyle() {
      let inner = this.propsData.params.goodsItemInnerSpace || "0";
      let css = {};
      if (inner) {
        css["padding"] = `${inner}px`;
      }
      return css;
    },
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.template-section {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .content-center {
    padding: 0 3.2%;
    display: flex;
    flex-wrap: wrap;
  }
  .goods-item {
    width: 50%;
    float: left;
    .goods-box {
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
    }
    .goods-fill-box {
      background: #ffffff;
      position: relative;
      border-radius: 5px;
    }
    .goods-banner {
      width: 100%;
      // height: 170px;
      background: #f2f2f2;
      border-radius: 5px 5px 0px 0px;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
      .default-img {
        width: 100px;
        height: 77px;
      }
    }
    .goods-info {
      width: 100%;
      padding: 0 8px;
      .goods-name {
        margin-top: 4px;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 600;
        color: rgba(29, 29, 29, 0.94);
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2; /* 这里是超出几行省略 */
        overflow: hidden;
        margin-bottom: 0;
      }
      .price-box {
        display: flex;
        align-items: flex-end;
        margin-top: 6px;
        .price {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 600;
          line-height: 17px;
          color: #fa2c1b;
          span:nth-child(2) {
            font-size: 19px;
          }
        }
        .origin-price {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 17px;
          color: #9b9b9b;
          text-decoration: line-through;
        }
      }
      .sales {
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 17px;
        color: #9b9b9b;
        margin-bottom: 8px;
        margin-top: 5px;
      }
      .buy-btn {
        position: absolute;
        right: 8px;
        bottom: 0px;
        width: 24px;
        height: 24px;
        border-radius: 8px;
        display: flex;
        justify-content: center;
        align-items: center;
        .iconfont {
          font-size: 19px;
          color: #ffffff;
        }
        .icon-weibiaoti-14 {
          font-size: 20px;
          color: #333333;
        }
      }
      .buy-text {
        height: 24px;
        padding: 0 10px;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #ffffff;
        line-height: 24px;
        position: absolute;
        background-color: #fa2c1b;
        right: 8px;
        bottom: 12px;
        border-radius: 60px;
      }
    }
  }
  .goods-item:nth-child(1) {
    margin-top: 0 !important;
  }
  .goods-item:nth-child(2) {
    margin-top: 0 !important;
  }
  .goods-item:nth-child(even) {
    .goods-box {
      margin-right: 0 !important;
    }
    padding-right: 0 !important;
  }
  .goods-item:nth-child(odd) {
    .goods-box {
      margin-left: 0 !important;
    }
    padding-right: 0 !important;
  }
  .storeInfo {
    width: 100%;
    border-top: 1px solid #f8f8f8;
    padding: 8px 0;
    display: flex;
    align-items: center;
    .pic {
      width: 27px;
      min-width: 27px;
      height: 27px;
      border: 1px solid #f5f5f5;
      border-radius: 2px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .info {
      flex: auto;
      margin-left: 5px;
      width: 0;
      display: flex;
      flex-direction: column;
      span:nth-child(1) {
        width: 100%;
        color: #262626;
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      span:nth-child(2) {
        width: 100%;
        color: #8c8c8c;
        font-size: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>
